package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.WdyBanner;
import com.ruoyi.system.service.IWdyBannerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-12-31
 */
@Controller
@RequestMapping("/system/wdyBanner")
public class WdyBannerController extends BaseController
{
    private String prefix = "system/wdyBanner";
	
	@Autowired
	private IWdyBannerService wdyBannerService;
	
	@RequiresPermissions("system:wdyBanner:view")
	@GetMapping()
	public String wdyBanner()
	{
	    return prefix + "/wdyBanner";
	}
	
	/**
	 * 查询广告列表
	 */
	@RequiresPermissions("system:wdyBanner:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WdyBanner wdyBanner)
	{
		startPage();
        List<WdyBanner> list = wdyBannerService.selectWdyBannerList(wdyBanner);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出广告列表
	 */
	@RequiresPermissions("system:wdyBanner:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WdyBanner wdyBanner)
    {
    	List<WdyBanner> list = wdyBannerService.selectWdyBannerList(wdyBanner);
        ExcelUtil<WdyBanner> util = new ExcelUtil<WdyBanner>(WdyBanner.class);
        return util.exportExcel(list, "wdyBanner");
    }
	
	/**
	 * 新增广告
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存广告
	 */
	@RequiresPermissions("system:wdyBanner:add")
	@Log(title = "广告", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WdyBanner wdyBanner)
	{		
		return toAjax(wdyBannerService.insertWdyBanner(wdyBanner));
	}

	/**
	 * 修改广告
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		WdyBanner wdyBanner = wdyBannerService.selectWdyBannerById(id);
		mmap.put("wdyBanner", wdyBanner);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存广告
	 */
	@RequiresPermissions("system:wdyBanner:edit")
	@Log(title = "广告", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WdyBanner wdyBanner)
	{		
		return toAjax(wdyBannerService.updateWdyBanner(wdyBanner));
	}
	
	/**
	 * 删除广告
	 */
	@RequiresPermissions("system:wdyBanner:remove")
	@Log(title = "广告", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wdyBannerService.deleteWdyBannerByIds(ids));
	}
	
}
